package com.parktech.sun.web.controller;

import com.parktech.sun.domain.model.Constants;
import com.parktech.sun.domain.repository.Page;
import com.parktech.sun.domain.service.industryinfo.IndustryInfoService;
import com.parktech.sun.domain.service.news.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * User: Think
 * Date: 11-1-18
 * Time: 上午2:33
 */
@Controller
@RequestMapping("/industryinfos")
public class IndustryInfoViewController extends BaseViewController {

    private int pageSize = Constants.PAGINATION_PAGE_SIZE;

    private IndustryInfoService industryInfoService;

    @Autowired
    public IndustryInfoViewController(IndustryInfoService industryInfoService) {
        this.industryInfoService = industryInfoService;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    @RequestMapping("/{categoryId}/pages/{pageNo}")
    public String view(@PathVariable("categoryId") Long categoryId, @PathVariable("pageNo") int pageNo, Model model) {
        Page page = new Page(pageSize, pageNo);
        model.addAttribute(industryInfoService.getByCategoryId(categoryId));
        model.addAttribute(industryInfoService.pageBy(categoryId, page));
        return "industryInfos";
    }

    @RequestMapping("/{industryInfoId}")
    public String viewDetail(@PathVariable("industryInfoId") Long industryInfoId, Model model) {
        model.addAttribute(industryInfoService.getById(industryInfoId));
        return "industryInfoDetail";
    }
}
